from tkinter import *
from function import *
import matplotlib.pyplot as ply

ply.plot()

threads = []

# --------------- 屏幕 ------------------------
screen = Tk()  # 主屏幕
screen.geometry("250x250")  # 窗体大小

# ---------------- 参数 ---------------------------
v = StringVar()  # 结果
a = StringVar()  # 二次系数
b = StringVar()  # 一次系数
c = StringVar()  # 常数

numOption = {
    'num': 0
}


def doOperation():
    print('开始运算')
    t = cThread()
    t.start()
    threads.append(t)


def stopOperation():
    for t in threads:
        t.stop()
    print("停止运算")

def showResult():
    numOption['num'] = 0
    for t in threads:
        numOption['num'] += t.result()
        x, y = t.showTable()
        ply.plot(x, y)
    v.set(numOption['num'])
    ply.show()


option1 = {
    'text': '开始运算',
}
startButton = Button(screen, command=doOperation, **option1)  # 按钮

option2 = {
    'text': '停止运算',
}
stopButton = Button(screen, command=stopOperation, **option2)  # 按钮

option3 = {
    'text': '显示结果',
}
labelOption = {
    'text': numOption['num']
}
showButton = Button(screen, command=showResult, **option3)  # 按钮
label = Label(screen, textvariable=v)  # 显示

startButton.pack()
stopButton.pack()
showButton.pack()
label.pack()

screen.mainloop()
